📌 case '/login':
return require "./views/login.php";
case '/login_check':
$u = @$_POST["user"];
$p = @$_POST["pass"];
$sql = new sql( );
$sql -> config("root","","shop","user");
$sql -> put_data(['id','uid','name','password']);
$data = $sql -> sel();
$check = false;
foreach($data as $key => $val)
{
if($data[$key]['name'] == $u)
{
if($data[$key]['pass'] == md5($p))
{
$check = true;
}
}
}
if($check)
{
//echo 'alert(\'登入成功\')';
header('refresh:0;url="/"');
}
else
{
//echo 'alert(\'登入失敗\')';
header('refresh:0;url="/"');
}
/login → 登入頁面
/login_check → 處理登入資料,透過資料庫去比對
📌 foreach($data as $key => $val)
{
if($data[$key]['name'] == $u)
{
if($data[$key]['pass'] == md5($p))
{
$check = true;
}
}
}
讀取資料庫的資料,放入$data
$key → 第幾筆資料
$data[$key]['name'] → 會員名稱
$data[$key]['pass'] → 會員密碼
📌 <div class = view>
<form action='/login_check' method=POST>
<div class = item>
<span>帳號<span>
<input type = text name=user>
</div>
<div class = item>
<span>密碼<span>
<input type = password name=pass>
</div>
<div class = item>
<input type = submit value=確認>
</div>
</form>
</div>
跟註冊頁面很像,但少了再次密碼確認
程式碼收錄:https://github.com/chyhhwen/shopping-system